<template>
  <div class="background-check-list-container">
    <div class="page-header">
      <h2>政审信息管理</h2>
      <p>管理党员发展对象的政治审查记录</p>
    </div>

    <!-- 统计卡片区域 -->
    <el-row :gutter="20" class="stat-cards">
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-blue">
              <el-icon>
                <Check />
              </el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.totalCount }}</div>
              <div class="stat-label">政审记录总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-green">
              <el-icon>
                <User />
              </el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.userCount }}</div>
              <div class="stat-label">政审对象人数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-orange">
              <el-icon>
                <CircleCheck />
              </el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.passRate }}%</div>
              <div class="stat-label">通过率</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-purple">
              <el-icon>
                <Timer />
              </el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.avgDuration }}天</div>
              <div class="stat-label">平均审查周期</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 搜索和操作区域 -->
    <el-card class="search-card" shadow="hover">
      <div class="search-container">
        <el-form :inline="true" :model="searchForm" class="search-form">
          <el-form-item label="政审对象">
            <el-input v-model="searchForm.name" placeholder="请输入姓名" clearable @clear="handleInputClear('name')"
              @input="debounceSearch" />
          </el-form-item>
          <el-form-item label="政审类型">
            <el-select v-model="searchForm.type" placeholder="请选择政审类型" clearable @change="handleTypeChange">
              <el-option label="入党政审" value="party_admission" />
              <el-option label="积极分子政审" value="full_membership" />
              <el-option label="发展对象政审" value="cadre_check" />
              <el-option label="预备党员政审" value="special_check" />
              <el-option label="正式党员政审" value="annual_review" />
            </el-select>
          </el-form-item>
          <el-form-item label="审查结果">
            <el-select v-model="searchForm.result" placeholder="请选择结果" clearable @change="handleResultChange">
              <el-option label="通过" value="pass" />
              <el-option label="不通过" value="fail" />
              <el-option label="待定" value="pending" />
              <el-option label="需补充材料" value="supplement" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchBackgroundChecks">
              <el-icon>
                <Search />
              </el-icon> 搜索
            </el-button>
            <el-button @click="resetSearch">
              <el-icon>
                <Refresh />
              </el-icon> 重置
            </el-button>
            <el-button type="success" @click="handleAdd">
              <el-icon>
                <Plus />
              </el-icon> 新增政审记录
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <!-- 政审记录列表表格 -->
    <el-card class="table-card" shadow="hover" v-loading="loading">
      <el-table :data="backgroundCheckList" border style="width: 100%" row-key="id">
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column prop="name" label="政审对象" min-width="100" />
        <el-table-column prop="type" label="政审类型" min-width="120">
          <template #default="scope">
            {{ getTypeText(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column prop="start_date" label="开始日期" min-width="120" />
        <el-table-column prop="end_date" label="结束日期" min-width="120" />
        <el-table-column prop="duration" label="审查周期" width="100" align="center">
          <template #default="scope">
            {{ scope.row.duration }}天
          </template>
        </el-table-column>
        <el-table-column prop="team" label="政审小组" min-width="100" />
        <el-table-column prop="result" label="结果" min-width="100">
          <template #default="scope">
            <el-tag :type="getResultTagType(scope.row.result)">{{ getResultText(scope.row.result) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="120">
          <template #default="scope">
            <div class="action-buttons">
              <el-button size="small" type="primary" plain @click="handleView(scope.row)">
                <el-icon>
                  <View />
                </el-icon> 查看
              </el-button>
              <el-button size="small" type="warning" plain @click="handleEdit(scope.row)">
                <el-icon>
                  <Edit />
                </el-icon> 编辑
              </el-button>
              <el-button size="small" type="danger" plain @click="handleDelete(scope.row)">
                <el-icon>
                  <Delete />
                </el-icon> 删除
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </el-card>

    <!-- 查看政审详情对话框 -->
    <el-dialog v-model="viewDialogVisible" title="政审详情" width="800px" :close-on-click-modal="false">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="政审对象">{{ currentBackgroundCheck.name }}</el-descriptions-item>
        <el-descriptions-item label="政审类型">{{ getTypeText(currentBackgroundCheck.type) }}</el-descriptions-item>
        <el-descriptions-item label="开始日期">{{ currentBackgroundCheck.start_date }}</el-descriptions-item>
        <el-descriptions-item label="结束日期">{{ currentBackgroundCheck.end_date }}</el-descriptions-item>
        <el-descriptions-item label="审查周期">{{ currentBackgroundCheck.duration }}天</el-descriptions-item>
        <el-descriptions-item label="政审小组">{{ currentBackgroundCheck.team || '无' }}</el-descriptions-item>
        <el-descriptions-item label="结果">
          <el-tag :type="getResultTagType(currentBackgroundCheck.result)">{{
            getResultText(currentBackgroundCheck.result)
          }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="核实方式" :span="2">
          <el-tag v-for="method in currentBackgroundCheck.methods" :key="method" class="method-tag">{{
            getMethodText(method)
          }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="调查内容" :span="2">
          <div class="background-check-content">
            {{ currentBackgroundCheck.content || '暂无内容' }}
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="主要问题" :span="2">
          <div class="background-check-issues">
            {{ currentBackgroundCheck.issues || '无' }}
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="结论意见" :span="2">
          <div class="background-check-conclusion">
            {{ currentBackgroundCheck.conclusion || '暂无结论' }}
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="viewDialogVisible = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 新增/编辑政审记录对话框 -->
    <el-dialog v-model="editDialogVisible" :title="isEdit ? '编辑政审记录' : '新增政审记录'" width="800px"
      :close-on-click-modal="false">
      <el-form :model="backgroundCheckForm" :rules="backgroundCheckFormRules" ref="backgroundCheckFormRef"
        label-width="100px">
        <el-form-item label="政审对象" prop="name">
          <template v-if="isEdit">
            <el-input v-model="backgroundCheckForm.name" placeholder="请输入姓名" disabled />
          </template>
          <template v-else>
            <el-select v-model="backgroundCheckForm.applicantId" filterable placeholder="请选择政审对象"
              @change="handleUserChange">
              <el-option v-for="user in userList" :key="user.id" :label="user.name || user.nickname || user.username"
                :value="user.id" />
            </el-select>
          </template>
        </el-form-item>
        <el-form-item label="政审类型" prop="type">
          <el-select v-model="backgroundCheckForm.type" placeholder="请选择政审类型">
            <el-option label="入党政审" value="party_admission" />
            <el-option label="积极分子政审" value="full_membership" />
            <el-option label="发展对象政审" value="cadre_check" />
            <el-option label="预备党员政审" value="special_check" />
            <el-option label="正式党员复查" value="annual_review" />
          </el-select>
        </el-form-item>
        <el-form-item label="审查时间" prop="dateRange">
          <el-date-picker v-model="backgroundCheckForm.dateRange" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss" />
        </el-form-item>
        <el-form-item label="政审小组" prop="team">
          <el-input v-model="backgroundCheckForm.team" placeholder="请输入政审小组成员姓名，多人用逗号分隔" />
        </el-form-item>
        <el-form-item label="核实方式" prop="methods">
          <el-checkbox-group v-model="backgroundCheckForm.methods">
            <el-checkbox label="interview">个别谈话</el-checkbox>
            <el-checkbox label="document">查阅档案</el-checkbox>
            <el-checkbox label="home_visit">家访</el-checkbox>
            <el-checkbox label="work_visit">单位走访</el-checkbox>
            <el-checkbox label="online_check">网络核查</el-checkbox>
            <el-checkbox label="reference">证明材料</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="调查内容" prop="content">
          <el-input v-model="backgroundCheckForm.content" type="textarea" :rows="5" placeholder="请输入政审调查内容" />
        </el-form-item>
        <el-form-item label="主要问题" prop="issues">
          <el-input v-model="backgroundCheckForm.issues" type="textarea" :rows="3" placeholder="请输入政审中发现的主要问题" />
        </el-form-item>
        <el-form-item label="结论意见" prop="conclusion">
          <el-input v-model="backgroundCheckForm.conclusion" type="textarea" :rows="3" placeholder="请输入政审结论意见" />
        </el-form-item>
        <el-form-item label="审查结果" prop="result">
          <el-radio-group v-model="backgroundCheckForm.result">
            <el-radio label="pass">通过</el-radio>
            <el-radio label="fail">不通过</el-radio>
            <el-radio label="pending">待定</el-radio>
            <el-radio label="supplement">需补充材料</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="editDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitBackgroundCheck" :loading="submitting">保存</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import {
  Search, Refresh, View, Edit, Delete, Plus, Check,
  User, CircleCheck, Timer
} from '@element-plus/icons-vue';
import {
  getBackgroundCheckList,
  getBackgroundCheckCount,
  saveOrUpdateBackgroundCheck,
  deleteBackgroundCheck,
  getBackgroundCheckStats
} from '@/api/backgroundCheck';
import { getUserList } from '@/api/user';

// 分页相关
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const loading = ref(false);
const backgroundCheckList = ref([]);

// 统计数据
const statsData = reactive({
  totalCount: 0,
  userCount: 0,
  passRate: 0,
  avgDuration: 0
});

// 搜索表单
const searchForm = reactive({
  name: '',
  type: '',
  result: ''
});

// 详情对话框
const viewDialogVisible = ref(false);
const currentBackgroundCheck = ref({});

// 编辑对话框
const editDialogVisible = ref(false);
const isEdit = ref(false);
const backgroundCheckFormRef = ref(null);
const backgroundCheckForm = reactive({
  id: '',
  applicantId: null, // 申请人ID
  name: '',
  type: '',
  dateRange: [],
  startDate: '',
  endDate: '',
  duration: 0,
  team: '',
  methods: ['interview', 'document'],
  content: '',
  issues: '',
  conclusion: '',
  result: 'pass'
});
const submitting = ref(false);

// 表单校验规则
const backgroundCheckFormRules = {
  applicantId: [{ required: true, message: '请选择政审对象', trigger: 'change' }],
  name: [{ required: true, message: '政审对象不能为空', trigger: 'blur' }],
  type: [{ required: true, message: '请选择政审类型', trigger: 'change' }],
  dateRange: [{ required: true, message: '请选择审查时间', trigger: 'change' }],
  methods: [{ type: 'array', required: true, message: '请至少选择一种核实方式', trigger: 'change' }],
  content: [{ required: true, message: '请输入调查内容', trigger: 'blur' }],
  conclusion: [{ required: true, message: '请输入结论意见', trigger: 'blur' }],
  result: [{ required: true, message: '请选择审查结果', trigger: 'change' }]
};

// 用户列表
const userList = ref([]);

// 获取用户列表
const fetchUserList = async () => {
  try {
    const response = await getUserList();
    if (response.data.code === 200) {
      userList.value = response.data.data.users || [];
    } else {
      console.error('获取用户列表失败:', response.data.msg);
    }
  } catch (error) {
    console.error('获取用户列表失败:', error);
  }
};

// 初始化加载数据
onMounted(() => {
  fetchBackgroundChecks();
  fetchUserList();
});

const formatDate = (dateTimeStr, includeTime = false) => {
  if (!dateTimeStr) return '-';
  // 后端返回的是 LocalDateTime 字符串，通常是 "YYYY-MM-DDTHH:mm:ss" 或 "YYYY-MM-DD HH:mm:ss"
  if (includeTime) {
    return dateTimeStr.replace('T', ' ').substring(0, 19); // YYYY-MM-DD HH:mm:ss
  }
  return dateTimeStr.substring(0, 10); // YYYY-MM-DD
};


// 获取政审记录列表
const fetchBackgroundChecks = async () => {
  loading.value = true;
  try {
    // 构建查询参数
    const queryData = {
      name: searchForm.name,
      type: searchForm.type,
      result: searchForm.result
    };

    // 1. 获取总数
    const countResponse = await getBackgroundCheckCount(queryData);
    if (countResponse.data.code === 200) {
      total.value = countResponse.data.data || 0;
    } else {
      ElMessage.error(countResponse.data.msg || '获取政审记录总数失败');
      loading.value = false;
      return;
    }

    // 2. 获取分页列表
    const response = await getBackgroundCheckList(queryData, currentPage.value, pageSize.value);

    if (response.data.code === 200) {
      console.log(response.data.data.page.records);
      const records = response.data.data.page.records || [];

      backgroundCheckList.value = records.map(item => ({
        id: item.id,
        applicantId: item.applicantId,
        name: item.name,
        type: item.type,
        start_date: formatDate(item.startDate, false),
        end_date: formatDate(item.endDate, false),
        duration: item.duration,
        team: item.team,
        methods: item.methods ? item.methods.split(',') : [],
        content: item.content,
        issues: item.issues,
        conclusion: item.conclusion,
        result: item.result
      }));

      // 获取统计数据
      fetchStatsData();
    } else {
      ElMessage.error(response.data.msg || '获取政审记录列表失败');
    }
  } catch (error) {
    console.error('获取政审记录列表失败:', error);
    ElMessage.error('获取政审记录列表失败，请稍后重试');
  } finally {
    loading.value = false;
  }
};

// 获取统计数据
const fetchStatsData = async () => {
  try {
    const response = await getBackgroundCheckStats();

    if (response.data.code === 200) {
      // 计算总数
      statsData.totalCount = total.value;

      // 计算涉及的政审对象人数（去重）
      const uniqueNames = new Set();
      backgroundCheckList.value.forEach(item => uniqueNames.add(item.name));
      statsData.userCount = uniqueNames.size;

      // 计算通过率
      let passCount = 0;
      const resultStats = response.data.data || {};

      if (resultStats.pass) {
        passCount = resultStats.pass;
      }

      statsData.passRate = statsData.totalCount > 0
        ? Math.round((passCount / statsData.totalCount) * 100)
        : 0;

      // 计算平均审查周期
      let totalDuration = 0;
      backgroundCheckList.value.forEach(item => {
        totalDuration += item.duration;
      });
      statsData.avgDuration = backgroundCheckList.value.length
        ? Math.round(totalDuration / backgroundCheckList.value.length)
        : 0;
    }
  } catch (error) {
    console.error('获取统计数据失败:', error);
  }
};

// 搜索政审记录
const searchBackgroundChecks = () => {
  currentPage.value = 1;
  fetchBackgroundChecks();
};

// 重置搜索条件
const resetSearch = () => {
  Object.keys(searchForm).forEach(key => {
    searchForm[key] = '';
  });
  currentPage.value = 1;
  fetchBackgroundChecks();
};

// 处理分页大小变化
const handleSizeChange = (val) => {
  pageSize.value = val;
  fetchBackgroundChecks();
};

// 处理页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val;
  fetchBackgroundChecks();
};

// 处理输入框清除
const handleInputClear = (key) => {
  searchForm[key] = '';
  fetchBackgroundChecks();
};

// 处理类型变化
const handleTypeChange = () => {
  fetchBackgroundChecks();
};

// 处理结果变化
const handleResultChange = () => {
  fetchBackgroundChecks();
};

// 获取政审类型文本
const getTypeText = (type) => {
  const types = {
    party_admission: '入党政审',
    full_membership: '积分分子政审',
    cadre_check: '发展对象政审',
    special_check: '预备党员政审',
    annual_review: '正式党员复查'
  };
  return types[type] || type;
};

// 获取核实方式文本
const getMethodText = (method) => {
  const methods = {
    interview: '个别谈话',
    document: '查阅档案',
    home_visit: '家访',
    work_visit: '单位走访',
    online_check: '网络核查',
    reference: '证明材料'
  };
  return methods[method] || method;
};

// 获取结果文本
const getResultText = (result) => {
  const results = {
    pass: '通过',
    fail: '不通过',
    pending: '待定',
    supplement: '需补充材料'
  };
  return results[result] || result;
};

// 获取结果标签类型
const getResultTagType = (result) => {
  const types = {
    pass: 'success',
    fail: 'danger',
    pending: 'info',
    supplement: 'warning'
  };
  return types[result] || '';
};

// 查看政审详情
const handleView = (row) => {
  currentBackgroundCheck.value = { ...row };
  viewDialogVisible.value = true;
};

// 编辑政审记录
const handleEdit = (row) => {
  isEdit.value = true;

  // 复制行数据到表单
  backgroundCheckForm.id = row.id;
  backgroundCheckForm.name = row.name;
  backgroundCheckForm.type = row.type;
  backgroundCheckForm.dateRange = [row.start_date, row.end_date];
  backgroundCheckForm.startDate = row.start_date;
  backgroundCheckForm.endDate = row.end_date;
  backgroundCheckForm.duration = row.duration;
  backgroundCheckForm.team = row.team;
  backgroundCheckForm.methods = Array.isArray(row.methods) ? [...row.methods] :
    (row.methods ? row.methods.split(',') : []);
  backgroundCheckForm.content = row.content;
  backgroundCheckForm.issues = row.issues || '';
  backgroundCheckForm.conclusion = row.conclusion;
  backgroundCheckForm.result = row.result;

  editDialogVisible.value = true;
};

// 新增政审记录
const handleAdd = () => {
  isEdit.value = false;

  // 重置表单
  backgroundCheckForm.id = '';
  backgroundCheckForm.applicantId = null; // 重置申请人ID
  backgroundCheckForm.name = '';
  backgroundCheckForm.type = '';
  backgroundCheckForm.dateRange = [];
  backgroundCheckForm.startDate = '';
  backgroundCheckForm.endDate = '';
  backgroundCheckForm.duration = 0;
  backgroundCheckForm.team = '';
  backgroundCheckForm.methods = ['interview', 'document'];
  backgroundCheckForm.content = '';
  backgroundCheckForm.issues = '';
  backgroundCheckForm.conclusion = '';
  backgroundCheckForm.result = 'pass';

  // 如果表单引用存在，重置验证状态
  if (backgroundCheckFormRef.value) {
    backgroundCheckFormRef.value.resetFields();
  }

  editDialogVisible.value = true;
};

// 删除政审记录
const handleDelete = (row) => {
  ElMessageBox.confirm(
    `确定要删除"${row.name}"的政审记录吗？此操作不可恢复！`,
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }
  ).then(async () => {
    try {
      const response = await deleteBackgroundCheck(row.id);

      if (response.data.code === 200) {
        ElMessage.success('删除政审记录成功');
        fetchBackgroundChecks(); // 重新加载数据
      } else {
        ElMessage.error(response.data.msg || '删除政审记录失败');
      }
    } catch (error) {
      console.error('删除政审记录失败:', error);
      ElMessage.error('删除政审记录失败，请稍后重试');
    }
  }).catch(() => { });
};

// 提交政审记录
const submitBackgroundCheck = async () => {
  if (!backgroundCheckFormRef.value) return;

  backgroundCheckFormRef.value.validate(async (valid) => {
    if (!valid) return;

    // 处理日期范围
    if (backgroundCheckForm.dateRange && backgroundCheckForm.dateRange.length === 2) {
      backgroundCheckForm.startDate = backgroundCheckForm.dateRange[0];
      backgroundCheckForm.endDate = backgroundCheckForm.dateRange[1];

      // 计算周期天数
      const startDate = new Date(backgroundCheckForm.startDate);
      const endDate = new Date(backgroundCheckForm.endDate);
      const diffTime = Math.abs(endDate - startDate);
      const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
      backgroundCheckForm.duration = diffDays + 1; // 包含开始日期和结束日期
    }

    // 处理methods数组，转为逗号分隔的字符串
    if (Array.isArray(backgroundCheckForm.methods)) {
      backgroundCheckForm.methods = backgroundCheckForm.methods.join(',');
    }

    submitting.value = true;
    try {
      // 调用API提交数据
      const submitData = {
        id: backgroundCheckForm.id || null,
        applicantId: backgroundCheckForm.applicantId, // 添加申请人ID
        name: backgroundCheckForm.name,
        type: backgroundCheckForm.type,
        startDate: backgroundCheckForm.startDate,
        endDate: backgroundCheckForm.endDate,
        duration: backgroundCheckForm.duration,
        team: backgroundCheckForm.team,
        methods: backgroundCheckForm.methods,
        content: backgroundCheckForm.content,
        issues: backgroundCheckForm.issues,
        conclusion: backgroundCheckForm.conclusion,
        result: backgroundCheckForm.result
      };

      const response = await saveOrUpdateBackgroundCheck(submitData);

      if (response.data.code === 200) {
        ElMessage.success(isEdit.value ? '更新政审记录成功' : '添加政审记录成功');
        editDialogVisible.value = false;
        fetchBackgroundChecks(); // 重新加载数据
      } else {
        ElMessage.error(response.data.msg || (isEdit.value ? '更新政审记录失败' : '添加政审记录失败'));
      }
    } catch (error) {
      console.error('提交政审记录失败:', error);
      ElMessage.error('提交政审记录失败，请稍后重试');
    } finally {
      submitting.value = false;
    }
  });
};

// 即时搜索
const debounceSearch = () => {
  fetchBackgroundChecks();
};

// 处理用户选择变化
const handleUserChange = (userId) => {
  if (!userId) {
    backgroundCheckForm.name = '';
    backgroundCheckForm.applicantId = null;
    return;
  }

  const selectedUser = userList.value.find(user => user.id === userId);
  if (selectedUser) {
    backgroundCheckForm.name = selectedUser.name || selectedUser.nickname || selectedUser.username;
    backgroundCheckForm.applicantId = selectedUser.id;
  }
};
</script>

<style scoped>
.background-check-list-container {
  padding: 20px;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 24px;
  color: #303133;
  margin: 0 0 8px 0;
}

.page-header p {
  font-size: 14px;
  color: #909399;
  margin: 0;
}

.stat-cards {
  margin-bottom: 20px;
}

.stat-card {
  margin-bottom: 20px;
}

.stat-card-content {
  display: flex;
  align-items: center;
  height: 100px;
  padding: 0 20px;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 15px;
}

.stat-icon .el-icon {
  font-size: 28px;
  color: white;
}

.bg-blue {
  background-color: #409EFF;
}

.bg-green {
  background-color: #67C23A;
}

.bg-orange {
  background-color: #E6A23C;
}

.bg-purple {
  background-color: #909399;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
  color: #303133;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.search-card {
  margin-bottom: 20px;
}

.search-container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
}

.table-card {
  margin-bottom: 20px;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.dialog-footer {
  padding-top: 20px;
  text-align: right;
}

.background-check-content,
.background-check-issues,
.background-check-conclusion {
  white-space: pre-line;
  padding: 10px;
  background-color: #f5f7fa;
  border-radius: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.action-buttons .el-button {
  margin-left: 0 !important;
  width: 100%;
}

.method-tag {
  margin-right: 5px;
  margin-bottom: 5px;
}

@media (max-width: 768px) {
  .search-container {
    flex-direction: column;
  }
}
</style>